local Click = require(SCRIPTS_DIR .. ".uikits.Click");
local ScrollCell = class("ScrollCell",function()
    return display.newNode();
end);

function ScrollCell:ctor(index,battleKind)
    local sprite = cc.Sprite:create(mgrs.res:getPngPath("yuchang_0" .. index));
    local size = sprite:getContentSize();
    self:setContentSize(size);
    sprite:setPosition(cc.p(size.width/2,size.height/2));
    self:addChild(sprite);
    local click = Click.new({targetNode = sprite});
    click:clickHandler(function()
        --mgrs.proto:send({msgid = Protocol.C2A_ROLE_OPERATION,opNum = 0,opType = operation_type.OPERATION_BATTLE_CREATE,opParam = index});
        --mgrs.player:setBattleChose(index,4);
    end);
    click:setSwallowEnabled(false);
    self.click = click;
end

function ScrollCell:setTouchTarget()
    self.click:setTouchTarget(false);
end


local BaseWnd = require(SCRIPTS_DIR .. ".wnds.BaseWnd");
local ChoseWnd = class("ChoseWnd",BaseWnd);
function ChoseWnd:ctor()
	ChoseWnd.super.ctor(self);
    self.scrollCells = {};
end

function ChoseWnd:onOpen()
    self.battleKind = self.wndData.param.battleKind; --普通  竞技
    self:setupClose("left.back");
    self:setRooms();
end

function ChoseWnd:setRooms()
    local sv = self:widget("middle.sv");
    local scrollView = self:createScrollView({sv = sv,dis = 10});
    for i=1,4 do
        local cell = ScrollCell.new(i,self.battleKind);
        scrollView:addContent(cell);
        table.insert(self.scrollCells,cell);
    end
    scrollView:setOnScrollCbk(function(event)
        if event.name == "clicked" then
            mgrs.log:printDebug("scrollView clicked");
        elseif event.name == "moved" then
            for key, var in pairs(self.scrollCells) do
                var:setTouchTarget();
            end
        end
    end);
    scrollView:addScrollNode();
end

function ChoseWnd:onClose()
	
end

function ChoseWnd:btnClicked()
    mgrs.log:printDebug("!!!!!TestWnd onClose!!!!!");
end



function ChoseWnd:reqData(handler)
	handler(true);	
end

function ChoseWnd:getLayer()
	return enums.Layer.Window;
end

function ChoseWnd:getPreloadResList()
	return {};
end

function ChoseWnd:isOpenCloseSoundEnabled()
	return false;
end

function ChoseWnd:onEnter()
	
end
function ChoseWnd:onExit()
	
end
function ChoseWnd:onEnterTransitionFinish()
	
end

function ChoseWnd:onExitTransitionStart()
	
end


mgrs.wnd:registerWnd(enums.Wnd.Chose,ChoseWnd);

--endregion
